/*
 * Modified file of CalendarActivity.java: Copyright (C) 2011 Chris Gao <chris@exina.net>
 *
 * Copyright (C) 2012  	Mathieu Marleix <mathieu.marleix@aerian.fr>
 * 						Sébastien Dufay
 * 						Romain Noel
 * 						Nicolas Dennewald
 * 						Slim Aloui
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.esiee.mobiliteam;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.URL;
import java.text.ParseException;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.esiee.mobiliteam.data.RSSFeed;
import org.esiee.mobiliteam.data.RSSItem;
import org.esiee.mobiliteam.handler.RSSHandler;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;

import android.app.Activity;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.preference.PreferenceManager;
import android.text.format.DateUtils;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsListView.LayoutParams;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;

/**
 * Show the month calendar view in the application.
 * The creation of the resources by date is also treated in this class.
 * 
 * @author Mathieu Marleix <mathieu.marleix@aerian.fr>
 * @author Sébastien Dufay
 * @author Romain Noel
 * @author Nicolas Dennewald
 * @author Slim Aloui
 *
 */
public class CalendarActivity extends Activity  implements CalendarView.OnCellTouchListener, OnItemClickListener, OnClickListener{
	private static final Exception Exception = null;
	public static final String MIME_TYPE = "vnd.android.cursor.dir/vnd.exina.android.calendar.date";
	SharedPreferences sharedPrefs = null;
	RSSFeed feed = null, globalFeed = null;
	CalendarView mView = null;
	static Date alarmdate = null;
	private Date lastDateRss = null;
	TextView mHit;
	Handler mHandler = new Handler();
	int month = 0, day = 0;
	ListView itemlist;
	ImageView ivnext, ivprev;
	boolean taskEnd = false, alarm_day_on = false, DEBUG = true;
	String RSS_URL = "";
	static final int ALARM_ID = 12345678;
	static Alarm alarm;
	/**
	 * Called on the first call of an activity.
	 */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.calendarview);
		mView = (CalendarView)findViewById(R.id.calendar);
		mView.setOnCellTouchListener(this);
		Date d = new Date();
		setDay(d.getDate());
		setMonth(d.getMonth());
		sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
		SharedPreferences.Editor memory = sharedPrefs.edit();
		memory.putString("dateLastRss" , RSSFeed.dateToString(new Date()));
		memory.commit();
		Thread thread = new Thread(new Runnable() {

			@Override
			public void run() {
				// TODO Auto-generated method stub
				setLastDate();
				launchResources(false);
			}
		});
		thread.start();
		setLabel();
		setImageListener();
	}
	public void setLastDate(){
		try {
			//On va chercher dans le fichier de preference la derniere date stockee.
			lastDateRss = RSSFeed.stringToDate(sharedPrefs.getString("dateLastRss", null));
			lastDateRss.setHours(lastDateRss.getHours()+10);
			if(DEBUG) System.out.println(lastDateRss.toLocaleString());
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			if(DEBUG) System.out.println("Reading file error\n");
			e.printStackTrace();
		}
	}
	/**
	 * Set listener on the two arrow's button
	 * on the view.
	 */
	private void setImageListener() {
		// TODO Auto-generated method stub
		ivprev = (ImageView) findViewById(R.id.prevMonth);
		ivprev.setClickable(true);
		ivprev.setOnClickListener(this);

		ivnext = (ImageView) findViewById(R.id.nextMonth);
		ivnext.setClickable(true);
		ivnext.setOnClickListener(this);
	}
	/**
	 * Set the text of the date
	 * selected on the calendar view
	 */
	public void setLabel(){
		mHandler.post(new Runnable() {
			public void run() {
				TextView tv = (TextView) findViewById(R.id.content_calendar);
				char[] stringArray = DateUtils.getMonthString(mView.getMonth(), DateUtils.LENGTH_LONG).toCharArray();
				stringArray[0] = Character.toUpperCase(stringArray[0]);
				tv.setText(getDay() + " " + new String(stringArray) + " "+mView.getYear());
			}
		});
	}
	/**
	 * Action when a cell is picked on the calendar.
	 */
	public void onTouch(Cell cell) {
		Intent intent = getIntent();
		String action = intent.getAction();
		if(action.equals(Intent.ACTION_PICK) || action.equals(Intent.ACTION_GET_CONTENT)) {
			setMonth(mView.getMonth());
			setDay(cell.getDayOfMonth());
			// FIX issue 6: make some correction on month and year
			if(cell instanceof CalendarView.GrayCell) {
				// oops, not pick current month...				
				if (getDay() < 15) {
					// pick one beginning day? then a next month day
					if(getMonth()==11)
					{
						setMonth(0);
					} else {
						setMonth(getMonth()+1);
					}

				} else {
					// otherwise, previous month
					if(getMonth()==0) {
						setMonth(11);
					} else {
						setMonth(getMonth()-1);
					}
				}
			}
			return;
		}
		setDay(cell.getDayOfMonth());
		setMonth(mView.getMonth());
		setLabel();
		Thread thread = new Thread(new Runnable() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				launchResources(false);
			}
		});
		thread.start();
	}
	/**
	 * Get the original feed of the ESIEE's planning.
	 */
	public void launchResources(boolean reload){
		sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);	
		try {
			if(!lastDateRss.after(new Date()) || !sharedPrefs.getBoolean("perform_synchro", true) || reload)  
					throw Exception;
			setGlobalFeed((RSSFeed) loadClassFile(new File(getCacheDir(),"rss.bin")));
			setFeed(getGlobalFeed());
			if(getFeed() == null) throw Exception;
		} catch (Exception e) {
			// TODO Auto-generated catch block
			String ressources = sharedPrefs.getString("ressources_ade", "");
			String matcheressources = RSSHandler.matchedDate("([0-9,]*[0-9]{1,5})",ressources);

			if(matcheressources.equals("")){
				Intent intent = new Intent(this, SettingsActivity.class);
				Bundle bundle = new Bundle();
				bundle.putString("activityChoice", "CalendarActivity");
				bundle.putBoolean("erreur", true);
				intent.putExtras(bundle);
				startActivity(intent);
				finish();
				return;
			}
			else if(ressources.startsWith("http")){
				matcheressources = RSSHandler.matchedDate("resources=([0-9,]*[0-9]{1,5})",ressources);
				RSS_URL = "http://planif.esiee.fr:8080/ade/rss?projectId=4&resources=" + matcheressources
						+ "&nbDays=30&x=26&y=2";
			}
			else {
				RSS_URL = "http://planif.esiee.fr:8080/ade/rss?projectId=4&resources=" + matcheressources
						+ "&nbDays=30&x=26&y=2";
			}
			setGlobalFeed(getFeed(RSS_URL));
			setFeed(getGlobalFeed());
			if(getFeed() != null){
				mHandler.post(new Runnable() {
					public void run() {
						saveClassFile(getFeed());
					}
				});
			}
			else Toast.makeText(CalendarActivity.this, R.string.no_save, Toast.LENGTH_LONG).show();
			if(DEBUG) System.out.println("CalendarActivity: Passage dans l'exception de launchRessource.\n");
		}
		//		TextView textview = (TextView) findViewById(R.id.content_rssActivity);
		//		textview.setText(date.toString());
		if(getFeed() != null){
			alarmDayOrNextDay();
			ListResourcesByDate(getDay(),getMonth());
			showListView();
		}
		else{
			showListView();
		}
	}
	/**
	 * Update the feed.
	 */
	public void reloadList(){
		if(DEBUG) System.out.println("CalendarActivity: Passage dans refresh.\n");
		launchResources(true);
	}
	/**
	 * Fonction de sauvegarde d'objet sur l'espace disque.
	 * @param o : l'objet à sauver.
	 */
	public void saveClassFile(Object o){
		boolean mExternalStorageAvailable = false;
		boolean mExternalStorageWriteable = false;
		String state = Environment.getExternalStorageState();

		if (Environment.MEDIA_MOUNTED.equals(state)) {
			// We can read and write the media
			mExternalStorageAvailable = mExternalStorageWriteable = true;
		} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
			// We can only read the media
			mExternalStorageAvailable = true;
			mExternalStorageWriteable = false;
		} else {
			// Something else is wrong. It may be one of many other states, but all we need
			//  to know is we can neither read nor write
			mExternalStorageAvailable = mExternalStorageWriteable = false;
		}
		if(mExternalStorageAvailable && mExternalStorageWriteable){
			ObjectOutputStream oos;
			try {
				oos = new ObjectOutputStream(new FileOutputStream(new File(this.getCacheDir(),"rss.bin"))); //Select where you wish to save the file...
				oos.writeObject(o); // write the class as an 'object'
				oos.flush(); // flush the stream to insure all of the information was written to 'save.bin'
				oos.close();// close the stream
				if(DEBUG) System.out.println("Saved! \n");
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				if(DEBUG) System.out.println("Writing file error\n");
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
	}
	/**
	 * Get the feed of the day and the month specified.
	 * @param day
	 * @param month
	 */
	public void ListResourcesByDate(int day, int month){
		getFeed().fillSortedItemList();
		TreeMap<Date, RSSItem> listDay = getFeed().getSortedItemList();
		TreeMap<Date, RSSItem> listDayAdd = new TreeMap<Date, RSSItem>();
		for(Date d : listDay.keySet()){
			if(d.getDate() == day && d.getMonth() == month){
				listDayAdd.put(d, listDay.get(d));
			}
		}
		getFeed().setSortedItemList(listDayAdd);
	}
	public void alarmDayOrNextDay(){
		getGlobalFeed().fillSortedItemList();
		TreeMap<Date, RSSItem> listDay2 = getGlobalFeed().getSortedItemList();
		getFeed().fillSortedItemList();
		TreeMap<Date, RSSItem> listDay = getFeed().getSortedItemList();
		Date d = new Date(), dayDate = null;
		if(day == d.getDate() && month == d.getMonth()){
			if(!listDay.isEmpty()) dayDate = listDay.firstKey();
			if(dayDate == null || !dayDate.after(d)){
				d.setDate(d.getDate()+1);
				TreeMap<Date, RSSItem> listDayAdd = new TreeMap<Date, RSSItem>();
				for(Date date : listDay2.keySet()){
					if(date.getDate() == d.getDate() && date.getMonth() == month){
						listDayAdd.put(date, listDay2.get(date));
					}
				}
				if(DEBUG) System.out.println("CalendarActivity: First Key " + listDayAdd.firstKey().getHours() + "\n");
				if(listDayAdd.firstKey().getHours() == 7) listDayAdd.remove(listDayAdd.firstKey());
				setAlarmdate(listDayAdd.firstKey());
			}
			else {
				if(listDay.firstKey().getHours() == 7) listDay.remove(listDay.firstKey());
				setAlarmdate(listDay.firstKey());
			}
		}
	}
	/**
	 * Chargement d'un objet ecrit dans un fichier.
	 * @param f : fichier où est stocké l'objet.
	 * @return : l'objet
	 * @throws Exception
	 */
	public Object loadClassFile(File f) throws Exception
	{
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(f));
		Object o = ois.readObject();
		return o;
	}
	/**
	 * Fonction récupérant le flux RSS.
	 * @param urlString : url à checker.
	 * @return le flux de type RSSHandler.
	 */
	private RSSFeed getFeed(String urlString)
	{
		try
		{
			
			SAXParserFactory factory = SAXParserFactory.newInstance();
			SAXParser parser = factory.newSAXParser();
			XMLReader xmlreader = parser.getXMLReader();

			RSSHandler rssHandler = new RSSHandler();
			xmlreader.setContentHandler(rssHandler);

			URL url = new URL(urlString);
			InputSource is = new InputSource(url.openStream());
			if(is != null) xmlreader.parse(is);

			return rssHandler.getFeed();
		}
		catch (Exception ee)
		{
			return null;
		}
	}
	/**
	 * Get the local feed
	 * @return feed
	 */
	public RSSFeed getFeed() {
		return feed;
	}
	/**
	 * Set the local feed
	 * @param feed
	 */
	public void setFeed(RSSFeed feed) {
		this.feed = feed;
	}
	/**
	 * Show the list in the listview itemlist
	 * if the list is empty print a message in a 
	 * textview.
	 */
	private void showListView()
	{
		final ListView l = new ListView(this);
		l.setId(R.id.itemlist);
		l.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT));
		l.setBackgroundResource(R.drawable.border);

		final TextView t = new TextView(this);
		t.setId(R.id.content_rssActivity);
		t.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.FILL_PARENT));
		t.setBackgroundResource(R.drawable.border);
		t.setGravity(Gravity.CENTER);
		t.setText(getString(R.string.no_event));
		
		if (getFeed() == null)
		{
			runOnUiThread(new Runnable() {
				LinearLayout ll;
				@Override
				public void run() {
					// TODO Auto-generated method stub
					itemlist = (ListView) findViewById(R.id.itemlist);
					if(itemlist != null)
						((LinearLayout) itemlist.getParent()).removeView(itemlist);
					TextView textview = (TextView) findViewById(R.id.content_rssActivity);
					if(textview == null){
						ll = (LinearLayout) findViewById(R.id.calendarlayout);
						t.setText(getString(R.string.error_rss));
						ll.addView(t);
					}
				}
			});
			return;
		}

		else{
			alarm_day_on = sharedPrefs.getBoolean("perform_day_alarm", false);
			boolean alarmChanged = this.getIntent().getExtras().getBoolean("alarmChanged",false);

			if(alarm_day_on) {
				if(DEBUG) System.out.println("CalendarActivity: AlarmChanged " + alarmChanged + "\n");
				if(!lastDateRss.after(new Date()) || alarmChanged){
					charger(getAlarmdate(), sharedPrefs);
					planifierAlarm();
				}
			}
		}


		List<Map<String,Object>> list = getFeed().fillItemList();

		if(list.size() == 0){
			runOnUiThread(new Runnable() {
				LinearLayout ll;
				@Override
				public void run() {
					itemlist = (ListView) findViewById(R.id.itemlist);
					if(itemlist != null)
						((LinearLayout) itemlist.getParent()).removeView(itemlist);
					TextView textview = (TextView) findViewById(R.id.content_rssActivity);
					if(textview == null){
						ll = (LinearLayout) findViewById(R.id.calendarlayout);
						ll.addView(t);
					}
				}
			});
			return ;
		}

		final SimpleAdapter adapter = new SimpleAdapter(this, list,
				android.R.layout.simple_list_item_2, new String[] { RSSItem.TITLE,RSSItem.DATE },
				new int[] { android.R.id.text1 , android.R.id.text2});

		setTaskEnd(false);

		runOnUiThread(new Runnable() {
			LinearLayout ll;
			TextView t;
			@Override
			public void run() {
				t = (TextView) findViewById(R.id.content_rssActivity);
				if(t != null)
					((LinearLayout) t.getParent()).removeView(t);
				itemlist = (ListView) findViewById(R.id.itemlist);
				if(itemlist == null){
					ll = (LinearLayout) findViewById(R.id.calendarlayout);
					ll.addView(l);
					itemlist = l;
				}
				itemlist.setAdapter(adapter); 
				itemlist.setSelection(0);
				setTaskEnd(true);
			}
		});
		while(!isTaskEnd())
			try {
				Thread.sleep(10L);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		if(list.size() != 0){
			itemlist.setOnItemClickListener(this);
		}
	}
	public static Date charger(Date dateAlarm, SharedPreferences sharedPrefs){
		alarm = new Alarm();
		Calendar cal = new GregorianCalendar();
		if(dateAlarm == null) return null;
		Date retourDate = (Date) dateAlarm.clone();

		retourDate.setMinutes(retourDate.getMinutes()-Integer.parseInt(sharedPrefs.getString("alarm_day_delay", "30")));
		cal.setTime(retourDate);
		alarm.setActive(false);
		alarm.setHeure(cal.get(Calendar.HOUR_OF_DAY));
		alarm.setDay(cal.get(Calendar.DAY_OF_MONTH));
		alarm.setMinute(cal.get(Calendar.MINUTE));

		SharedPreferences.Editor memory = sharedPrefs.edit();
		memory.putString("current_alarm_date" , retourDate.toLocaleString());
		memory.commit();
		return retourDate;
	}
	/**
	 * Listener on the object's list
	 */
	public void onItemClick(AdapterView<?> parent, View v, int position, long id) {
		// TODO Auto-generated method stub
		Intent itemintent = new Intent(this,ActivityShowDescription.class);

		Bundle b = new Bundle();
		b.putString("title", getFeed().getItem(position).getTitle());
		b.putString("description", getFeed().getItem(position).getDescription());
		b.putString("link", getFeed().getItem(position).getLink());
		b.putString("pubdate", getFeed().getItem(position).getPubDate());

		itemintent.putExtra("android.intent.extra.rssItem", b);
		startActivityForResult(itemintent, 0);
	}
	/**
	 * Get the local month
	 * @return month
	 */
	public int getMonth() {
		return month;
	}
	/**
	 * Set the local month
	 * @param month
	 */
	public void setMonth(int month) {
		this.month = month;
	}
	/**
	 * Get the local day
	 * @return day
	 */
	public int getDay() {
		return day;
	}
	/**
	 * Set the local day
	 * @param day
	 */
	public void setDay(int day) {
		this.day = day;
	}
	/**
	 * Generate the menu.
	 */
	public boolean onCreateOptionsMenu(Menu menu) {
		// refresh the tabs and their content
		//    	Toast.makeText(RSSFeed.this, "Option", Toast.LENGTH_SHORT).show();
		//Création d'un MenuInflater qui va permettre d'instancier un Menu XML en un objet Menu
		MenuInflater inflater = getMenuInflater();
		//Instanciation du menu XML spécifier en un objet Menu
		inflater.inflate(R.layout.menu, menu);
		return true;
	}
	/**
	 * Listener of the menu.
	 */
	public boolean onOptionsItemSelected(MenuItem item) {
		//On regarde quel item a été cliqué grâce à son id et on déclenche une action
		switch (item.getItemId()) {
		case R.id.option:
			Intent intent = new Intent(this, SettingsActivity.class);
			Bundle bundle = new Bundle();
			//Add the parameters to bundle as
			bundle.putBoolean("erreur", false);
			bundle.putString("activityChoice", "CalendarActivity");
			intent.putExtras(bundle);
			startActivity(intent);
			finish();
			return true;
		case R.id.month_view:
			Date date = new Date();
			Intent intent3 = new Intent(this,CalendarActivity.class);
			intent3.setAction(CalendarActivity.MIME_TYPE);
			Bundle bundle2 = new Bundle();
			date.setDate(date.getDate());
			bundle2.putInt("day", date.getDate());
			bundle2.putInt("month", date.getMonth());
			intent3.putExtras(bundle2);
			startActivity(intent3);
			finish();
			return true;
		case R.id.refresh_button:
			reloadList();
			return true;
		case R.id.list_view:
			Intent intent2 = new Intent(this, TabWidget.class);
			Bundle bundle3 = new Bundle();
			bundle3.putString("activityChoice", "RssActivity");
			intent2.putExtras(bundle3);
			startActivity(intent2);
			finish();
			return true;
		case R.id.quitter:
			finish();
		}
		return false;
	}
	/**
	 * Synchronization boolean for thread
	 * true if the list is filled.
	 * @return taskend
	 */
	public boolean isTaskEnd() {
		return taskEnd;
	}
	/**
	 * Set the synchronization boolean.
	 * @param taskEnd
	 */
	public void setTaskEnd(boolean taskEnd) {
		this.taskEnd = taskEnd;
	}
	/**
	 * Action provoked when clicked on an
	 * arrow of the view. 
	 */
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if(v.equals(ivprev)){
			mView.previousMonth();
			setMonth(mView.getMonth());
			setLabel();
			Thread thread = new Thread(new Runnable() {
				@Override
				public void run() {
					// TODO Auto-generated method stub
					launchResources(false);
				}
			});
			thread.start();
		}
		else if(v.equals(ivnext)){
			mView.nextMonth();
			setMonth(mView.getMonth());
			setLabel();
			Thread thread = new Thread(new Runnable() {
				@Override
				public void run() {
					// TODO Auto-generated method stub
					launchResources(false);
				}
			});
			thread.start();
		}
	}
	/**
	 * Job de planification de l'alarme
	 */
	private void planifierAlarm() {
		//Récupération de l'instance du service AlarmManager.
		AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

		//On instancie l'Intent qui va étre appelé au moment du alarme.
		Intent intent = new Intent(this, AlarmReceiver.class);
		//On créer le pending Intent qui identifie l'Intent de alarme avec un ID et un/des flag(s)
		PendingIntent pendingintent = PendingIntent.getBroadcast(this, ALARM_ID, intent, 0);

		//On annule l'alarm pour replanifier si besoin
		am.cancel(pendingintent);

		//La on va déclencher un calcul pour connaitre le temps qui nous sépare de la prochaine alarme.
		Calendar alarme  = Calendar.getInstance();
		alarme.set(Calendar.HOUR_OF_DAY, alarm.getHeure());
		alarme.set(Calendar.MINUTE, alarm.getMinute());
		alarme.set(Calendar.DAY_OF_MONTH, alarm.getDay());

		Calendar cal = Calendar.getInstance();
		alarme.set(Calendar.SECOND, 0);
		cal.set(Calendar.SECOND, 0);
		long diff = alarme.getTimeInMillis() - cal.getTimeInMillis();

		//On ajoute le alarme au service de l'AlarmManager
		am.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis() + diff, pendingintent);
		// 		Toast.makeText(this, "Alarme programmée le " + 
		// 				alarme.get(Calendar.DAY_OF_MONTH) + " à " + 
		// 				alarme.get(Calendar.HOUR_OF_DAY) + ":" + + 
		// 				alarme.get(Calendar.MINUTE), Toast.LENGTH_SHORT).show();
		if(DEBUG) System.out.println("CalendarActivity: Alarme journalière programmée le " + 
				alarme.get(Calendar.DAY_OF_MONTH) + " à " + 
				alarme.get(Calendar.HOUR_OF_DAY) + ":" + + 
				alarme.get(Calendar.MINUTE));
	}
	/**
	 * @return the globalFeed
	 */
	public RSSFeed getGlobalFeed() {
		return globalFeed;
	}
	/**
	 * @param globalFeed the globalFeed to set
	 */
	public void setGlobalFeed(RSSFeed globalFeed) {
		this.globalFeed = globalFeed;
	}
	/**
	 * @return the alarmdate
	 */
	public static Date getAlarmdate() {
		return alarmdate;
	}
	/**
	 * @param alarmdate the alarmdate to set
	 */
	public void setAlarmdate(Date alarmdate) {
		CalendarActivity.alarmdate = alarmdate;
	}
	/**
	 * @return the alarm
	 */
	public static Alarm getAlarm() {
		return alarm;
	}
	/**
	 * @param alarm the alarm to set
	 */
	public static void setAlarm(Alarm alarm) {
		CalendarActivity.alarm = alarm;
	}
}